package com.xt.purchasingsystem.controller;


import com.xt.purchasingsystem.dto.BuyerPlanDto;
import com.xt.purchasingsystem.model.BuyerPlan;
import com.xt.purchasingsystem.service.BuyerPlanService;
import com.xt.purchasingsystem.utils.Result;
import com.xt.purchasingsystem.utils.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 采购计划单所有接口
 * </p>
 *
 * @author yhp
 * @since 2020-05-31
 */
@RestController
@RequestMapping("/buyerPlan")
public class BuyerPlanController {
    @Autowired
    private BuyerPlanService buyerPlanService;

    /**
     * 添加采购计划单及其采购计划采购明细的接口
     *
     * @param buyerPlanDto
     * @return
     */
    @PostMapping
    public Result saveBuyerPlan(@RequestBody BuyerPlanDto buyerPlanDto) {
        return buyerPlanService.saveBuyerPlan(buyerPlanDto);
    }

    /**
     * 分页查询所有未审核的采购计划单及其采购计划采购明细的接口
     * @param currNo
     * @param pageSize
     * @return
     */
    @GetMapping("/{currNo}/{pageSize}")
    public Result getAllBuyerPlanNoCheck(@PathVariable Integer currNo,@PathVariable Integer pageSize) {
        return buyerPlanService.getAllBuyerPlanNoCheck(currNo,pageSize);
    }

    @PutMapping
    public Result checkBuyerPlan(@RequestBody BuyerPlan buyerPlan){
        boolean flag = buyerPlanService.updateById(buyerPlan);
        if (flag){
            return ResultFactory.buildSuccessResult("审核成功");
        }else {
            return ResultFactory.buildFailResult("审核失败");
        }
    }
}

